﻿using System.Data;
using DAO;
using DTO;
using System.Collections.Generic;

namespace BLO
{
    public class SanPham_Blo 
    {
        private readonly SanPham_Dao _sanPhamDao = new SanPham_Dao();

        public DataTable GetAllObject()
        {
            return _sanPhamDao.GetAllObject();
        }

        public SanPham_Dto GetSanPham(string masp)
        {
            if (string.IsNullOrEmpty(masp))
                return null;
            return _sanPhamDao.GetSanPham(masp);
        }

        public int AddObject(SanPham_Dto obj)
        {
            if (string.IsNullOrEmpty(obj.MaChatLieu) || string.IsNullOrEmpty(obj.MaLoai) ||
                string.IsNullOrEmpty(obj.MaNuoc) ||
                string.IsNullOrEmpty(obj.MaMau) || string.IsNullOrEmpty(obj.TenSP))
                return -1;
            return _sanPhamDao.AddObject(obj);
        }

        public int EditObject(string id, SanPham_Dto newObj)
        {
            if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(newObj.TenSP)) return -1;
            return _sanPhamDao.EditObject(id, newObj);
        }

        public int DeleteObject(string id)
        {
            if (string.IsNullOrEmpty(id)) return -1;
            return _sanPhamDao.DeleteObject(id);
        }

        public int AutoIncrementIdObject()
        {
            return _sanPhamDao.AutoIncrementIdObject();
        }

        public DataTable FindObject(string condition)
        {
            return _sanPhamDao.FindObject(condition);
        }

        public DataSet GetSanPhams(string makh, string manv)
        {
            if (string.IsNullOrEmpty(makh) || string.IsNullOrEmpty(manv))
                return null;
            return _sanPhamDao.GetSanPhams(makh, manv);
        }
    }
}